#include "NTdict.h"

void insert(NTdict_t *dict,unsigned int items)
{
	unsigned int i;
	char key[100];
	char value[100];
	for(i=0;i<items;i++)
	{
		sprintf(key,"key%d",i);
		sprintf(value,"value%d",i);
		NTdict_append(dict,key,value,strlen(value)+1);
	}
}

void insertLarge(NTdict_t *dict,unsigned int times)
{
	unsigned int i,vlen;
	char *largeK = (char *)malloc(5000);
	char *largeV = (char *)malloc(8000);
	sprintf(largeK,"key%03000d",12345678);
	vlen = sprintf(largeV,"value%04000d",99999);
	for(i=0;i<times;i++)
	{
		NTdict_append(dict,largeK,largeV,vlen+1);
	}
	free(largeK);
	free(largeV);
}

int main()
{
	NTdict_t *dict;
	
	char key[] = "key86";
	char *value;
	unsigned int vlen;
	int i;
	
	NTdict_init(&dict);
	insert(dict,1000000);
	//NTdict_print(dict);
	value = NTdict_query(dict,key,&vlen);
	if (value != NULL)
	{
		printf("%s -> %s[%d]\n",key,value,vlen);
	}
	NTdict_distory(dict);
	
	/*
	scanf("%d",&vlen);
	NTdict_init(&dict);
	insert(dict,100000);
	scanf("%d",&vlen);
	NTdict_distory(dict);
	*/
	scanf("%d",&vlen);
	
	for(i=0;i<500;i++){
		NTdict_init(&dict);
		insertLarge(dict,1000);
		NTdict_distory(dict);
	}
	scanf("%d",&vlen);	
	return 0;
}

